package 补充.网络编程;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class UDP网络程序接收 {
    public static void main(String[] args) throws IOException {
        DatagramSocket socket = new DatagramSocket(8081);
        byte[] buf = new byte[64];
        DatagramPacket packet = new DatagramPacket(buf, buf.length);
        System.out.println("等待接受数据");
        socket.receive(packet);
        String str = new String(packet.getData(),0,64);
        System.out.println(packet.getData());
        System.out.println(packet.getLength());
        System.out.println(str+"-->"+packet.getAddress()+":"+packet.getPort());
        socket.close();
    }
}
